#pragma once
#include <pcap.h>
#include <atomic>
#include <thread>
#include <iostream>
#include "IPParser.h"
#include "Statistics.h"

class PacketCapture {
public:
    PacketCapture();
    ~PacketCapture();

    bool selectInterface();
    void startCapture();
    void stopCapture();

private:
    pcap_t* handle = nullptr;
    std::atomic<bool> captureRunning{ false };
    std::thread captureThread;
    TrafficStatistics stats;

    void captureThreadFunc();
    static void packetHandler(u_char* userData, const struct pcap_pkthdr* pkthdr, const u_char* packet);
};